package com.kw.drug.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kw.drug.common.ResultMapUtil;
import com.kw.drug.entity.Returngoods;
import com.kw.drug.entity.Returnsupplier;
import com.kw.drug.entity.Supplier;
import com.kw.drug.service.ReturnSupplierService;
import com.kw.drug.service.ReturngoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/returnsupplier")
public class ReturnsupplierController {
    @Autowired
    ReturnSupplierService returnSupplierService;

    @RequestMapping()
    public String returnsupplier() {
        return "returnsupplier";
    }

    /**
     * 分页查询退货给供应商列表
     */
    @RequestMapping("/returnsupplierQueryPage")
    @ResponseBody
    public Map returnsupplierQueryPage(String param, @RequestParam(defaultValue = "1") int pageNum, @RequestParam(defaultValue = "10") int pageSize) {
        try {
            IPage<Returnsupplier> iPage = returnSupplierService.problemQueryPage(param, pageSize, pageNum);
            return ResultMapUtil.getHashMapMysqlPage(iPage);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }
    }

    /**
     * 去到编辑页面
     */
    @RequestMapping("/returnsupplierQueryById")
    public String updateIndex(Integer id, Model model) {

        Returnsupplier returnsupplier = returnSupplierService.selectreturnSupplierById(id);
        model.addAttribute("obj", returnsupplier);
        return "returnsupplierPage";
    }

    /**
     * 修改
     */
    @RequestMapping("/returnsupplierEdit")
    @ResponseBody
    public Map updateReturnsuppier(Returnsupplier returnsupplier) {
        try {
            Integer integer = returnSupplierService.updateSupplierById(returnsupplier);
            return ResultMapUtil.getHashMapSave(integer);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }

    }

    /**
     * 根据id删除
     */
    @RequestMapping("/returnsupplierDelById")
    @ResponseBody
    public Map returnsupplierDelById(Integer id) {
        try {
            Integer integer = returnSupplierService.deleteReturnsupplierById(id);
            return ResultMapUtil.getHashMapSave(integer);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }

    }

    /**
     * 进入添加页面
     */
    @RequestMapping("/returnsupplierPage")
    public String addIndex() {
        return "returnsupplierPage";
    }

    /**
     * 添加
     */


    @RequestMapping("/returnsupplierAdd")
    @ResponseBody
    public Map addReturnsupplierAdd(Returnsupplier returnsupplier) {
        try {
            Integer integer = returnSupplierService.addReturnsupplier(returnsupplier);
            return ResultMapUtil.getHashMapSave(integer);
        } catch (Exception e) {
            return ResultMapUtil.getHashMapException(e);
        }


    }
}
